package com.xing.util;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;

public class SharedPreferenceUtil {
	public static String SHAREDFRENCE_NAME = "questionnaire_survey";
	
	public static String userName = "user_name";
	public static String userPwd = "user_pwd";
	
	public static String isRememberUserName = "is_remember_username";
	public static String isRememberPwd = "is_remember_pwd";
	
	public static String HOST_IP = "host_ip";
	public static String PORT = "port";
	
	
	
	private static SharedPreferences sharedPreferences;
	
	public static SharedPreferences getSharedPreferences (Context context){
		if (sharedPreferences == null) {
			sharedPreferences = context.getSharedPreferences(SHAREDFRENCE_NAME, Context.MODE_WORLD_WRITEABLE);
		}
		return sharedPreferences;
	}

	public static void putStringInfo(Context context,String key,String info){
		Editor editor = getSharedPreferences(context).edit();
		editor.putString(key, info);
		editor.commit();
	}
	
    
    public static String getStringInfo(Context context,String key){
    	String info = getSharedPreferences(context).getString(key, "");
        return info;
    }
    
    public static void putBooleanInfo(Context context,String key,boolean flag){
    	Editor editor = getSharedPreferences(context).edit();
		editor.putBoolean(key, flag);
		editor.commit();
    }
    
    public static boolean getBooleanInfo(Context context,String key){
    	boolean flag = getSharedPreferences(context).getBoolean(key, false);
    	return flag;
    }
    
    public static void clearStringInfo(Context context,String key){
    	Editor editor = getSharedPreferences(context).edit();
		editor.putString(key, "");
		editor.commit();
    }
}
